package com.njupt.towersusers.controller;

import com.njupt.towersusers.domain.Drivers;
import com.njupt.towersusers.serivices.DriversService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/usr")
@CrossOrigin("*")
public class DriverCtrl {
    @Resource
    private DriversService driversService;

    @RequestMapping("/insertuser")
    public String insertUser(
            Drivers driver,
            @RequestParam(required = false,name = "driverphoto") MultipartFile usphoto,
            @RequestParam(required = false,name = "licensephoto") MultipartFile drivercard
    ){
        driversService.addDriver(driver,usphoto,drivercard);
        //调用服务类，将文件保存为临时文件
        //再将临时文件上传到fastdfs文件服务器上，并获得服务器上的返回路径和新图片名
        //再把服务器上的图片文件存放到driver对象中
        //再把driver对象存放到mysql数据库中
        return "{\"driverreg\":\"success\"}";
    }

    @RequestMapping("/deluser/{driverid}")
    public String delUser(@PathVariable("driverid") int driverid){
        System.out.println(driverid);
        return "{\"driverdestory\":\"success\"}";
    }

    @RequestMapping("/moduser")
    public String modUser(Drivers drivers){
        return "{\"drivermodify\":\"success\"}";
    }

    @RequestMapping("/findusers")
    public List<Drivers> findUsers(int pageSize,int pageNum){
        List<Drivers> drs=new ArrayList<>();
        drs.add(Drivers.builder().driverman("zs").driverid(12).driverage(40).build());
        drs.add(Drivers.builder().driverman("ls").driverid(13).driverage(28).build());
        return drs;
    }

    
    @RequestMapping("finduser")
    public List<Drivers> findUser(Drivers drivers){
        List<Drivers> drs=new ArrayList<>();
        return drs;
    }
}
